home *** CD-ROM | disk | FTP | other *** search
/ Windows Game Programming for Dummies (2nd Edition) / WinGamProgFD.iso / pc / DirectX SDK / DXSDK / samples / Multimedia / DirectShow / BaseClasses / dsschedule.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-10-09  |  4.3 KB  |  133 lines

  1. //------------------------------------------------------------------------------
  2. // File: DSSchedule.h (replaces DX8's schedule.h)
  3. //
  4. // Desc: DirectShow base classes.
  5. //
  6. // Copyright (c) 1996-2001 Microsoft Corporation.  All rights reserved.
  7. //------------------------------------------------------------------------------
  8.  
  9.  
  10. #ifndef __CAMSchedule__
  11. #define __CAMSchedule__
  12.  
  13. class CAMSchedule : private CBaseObject
  14. {
  15. public:
  16.     virtual ~CAMSchedule();
  17.     // ev is the event we should fire if the advise time needs re-evaluating
  18.     CAMSchedule( HANDLE ev );
  19.  
  20.     DWORD GetAdviseCount();
  21.     REFERENCE_TIME GetNextAdviseTime();
  22.  
  23.     // We need a method for derived classes to add advise packets, we return the cookie
  24.     DWORD_PTR AddAdvisePacket( const REFERENCE_TIME & time1, const REFERENCE_TIME & time2, HANDLE h, BOOL periodic );
  25.     // And a way to cancel
  26.     HRESULT Unadvise(DWORD_PTR dwAdviseCookie);
  27.  
  28.     // Tell us the time please, and we'll dispatch the expired events.  We return the time of the next event.
  29.     // NB: The time returned will be "useless" if you start adding extra Advises.  But that's the problem of
  30.     // whoever is using this helper class (typically a clock).
  31.     REFERENCE_TIME Advise( const REFERENCE_TIME & rtTime );
  32.  
  33.     // Get the event handle which will be set if advise time requires re-evaluation.
  34.     HANDLE GetEvent() const { return m_ev; }
  35.  
  36. private:
  37.     // We define the nodes that will be used in our singly linked list
  38.     // of advise packets.  The list is ordered by time, with the
  39.     // elements that will expire first at the front.
  40.     class CAdvisePacket
  41.     {
  42.     public:
  43.         CAdvisePacket()
  44.         {}
  45.  
  46.         CAdvisePacket * m_next;
  47.         DWORD_PTR       m_dwAdviseCookie;
  48.         REFERENCE_TIME  m_rtEventTime;      // Time at which event should be set
  49.         REFERENCE_TIME  m_rtPeriod;         // Periodic time
  50.         HANDLE          m_hNotify;          // Handle to event or semephore
  51.         BOOL            m_bPeriodic;        // TRUE => Periodic event
  52.  
  53.         CAdvisePacket( CAdvisePacket * next, LONGLONG time ) : m_next(next), m_rtEventTime(time)
  54.         {}
  55.  
  56.         void InsertAfter( CAdvisePacket * p )
  57.         {
  58.             p->m_next = m_next;
  59.             m_next    = p;
  60.         }
  61.  
  62.         int IsZ() const // That is, is it the node that represents the end of the list
  63.         { 
  64.             return m_next == 0; 
  65.         }
  66.  
  67.         CAdvisePacket * RemoveNext()
  68.         {
  69.             CAdvisePacket *const next = m_next;
  70.             CAdvisePacket *const new_next = next->m_next;
  71.             m_next = new_next;
  72.             return next;
  73.         }
  74.  
  75.         void DeleteNext()
  76.         {
  77.             delete RemoveNext();
  78.         }
  79.  
  80.         CAdvisePacket * Next() const
  81.         {
  82.             CAdvisePacket * result = m_next;
  83.             if (result->IsZ()) result = 0;
  84.             return result;
  85.         }
  86.  
  87.         DWORD_PTR Cookie() const
  88.         { 
  89.             return m_dwAdviseCookie; 
  90.         }
  91.     };
  92.  
  93.     // Structure is:
  94.     // head -> elmt1 -> elmt2 -> z -> null
  95.     // So an empty list is:       head -> z -> null
  96.     // Having head & z as links makes insertaion,
  97.     // deletion and shunting much easier.
  98.     CAdvisePacket   head, z;            // z is both a tail and a sentry
  99.  
  100.     volatile DWORD_PTR  m_dwNextCookie;     // Strictly increasing
  101.     volatile DWORD  m_dwAdviseCount;    // Number of elements on list
  102.  
  103.     CCritSec        m_Serialize;
  104.  
  105.     // AddAdvisePacket: adds the packet, returns the cookie (0 if failed)
  106.     DWORD_PTR AddAdvisePacket( CAdvisePacket * pPacket );
  107.     // Event that we should set if the packed added above will be the next to fire.
  108.     const HANDLE m_ev;
  109.  
  110.     // A Shunt is where we have changed the first element in the
  111.     // list and want it re-evaluating (i.e. repositioned) in
  112.     // the list.
  113.     void ShuntHead();
  114.  
  115.     // Rather than delete advise packets, we cache them for future use
  116.     CAdvisePacket * m_pAdviseCache;
  117.     DWORD           m_dwCacheCount;
  118.     enum { dwCacheMax = 5 };             // Don't bother caching more than five
  119.  
  120.     void Delete( CAdvisePacket * pLink );// This "Delete" will cache the Link
  121.  
  122. // Attributes and methods for debugging
  123. public:
  124. #ifdef DEBUG
  125.     void DumpLinkedList();
  126. #else
  127.     void DumpLinkedList() {}
  128. #endif
  129.  
  130. };
  131.  
  132. #endif // __CAMSchedule__
  133.